//
//  XBActivityCell.m
//  FindPreciousFrameWork
//
//  Created by TianZhen on 16/4/12.
//  Copyright © 2016年 MoreMoney. All rights reserved.
//
#import "UIImageView+WebCache.h"
#import "XBActivityCell.h"
#import "XBActivityModel.h"

@interface XBActivityCell ()
@property (nonatomic,weak) UIImageView *imgView;
@property (nonatomic,weak) UILabel *canyuLabel;
@property (nonatomic,weak) UILabel *zanLabel;
@property (nonatomic,weak) UIImageView *labelBackGroundView;
@end

@implementation XBActivityCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self setup];
    }
    return self;
}
#define screenW [UIScreen mainScreen].bounds.size.width
- (void)setup
{
    // 创建imageView
    UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, screenW-10, 180)];
    self.imgView = imgView;
    [self.contentView addSubview:imgView];
    
    // 文本背景
    UIImage *LabelBackGroundImage = [UIImage imageNamed:@"discovery_elite_activity_gradient"];
    // 创建文本背景
    UIImageView *labelBackGroundView = [[UIImageView alloc] initWithImage:LabelBackGroundImage];
    self.labelBackGroundView = labelBackGroundView;
    [self.contentView addSubview:labelBackGroundView];
    
    // 创建参与label 和 赞label
    UILabel *canyuLabel = [[UILabel alloc] init];
    UILabel *zanlabel = [[UILabel alloc] init];
    self.canyuLabel = canyuLabel;
    self.zanLabel = zanlabel;
    [self.contentView addSubview:canyuLabel];
    [self.contentView addSubview:zanlabel];
}

- (void)setModel:(XBActivityModel *)model
{
    _model = model;
    
    // 占位图
    UIImage *placeHolderImg = [UIImage imageNamed:@"私人订制1"];
    NSURL *imageURL = [NSURL URLWithString:model.imageURL];
    // 设置图片
    [self.imgView sd_setImageWithURL:imageURL placeholderImage:placeHolderImg];
    // 设置文本内容
    self.canyuLabel.text = [NSString stringWithFormat:@"参与 %zd",model.canyu];
    self.canyuLabel.textAlignment = NSTextAlignmentLeft;
    self.canyuLabel.textColor = [UIColor whiteColor];
    self.zanLabel.text = [NSString stringWithFormat:@"赞 %zd",model.zan];
    self.zanLabel.textAlignment = NSTextAlignmentLeft;
    self.zanLabel.textColor = [UIColor whiteColor];
    
    [self.canyuLabel sizeToFit];
    [self.zanLabel sizeToFit];
}
- (void)setFrame:(CGRect)frame
{
    frame.size.height -= 10;
    frame.size.width -= 10;
    frame.origin.x += 5;
    [super setFrame:frame];
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    // 图片高度(cell高)
    CGFloat imageH = self.imgView.frame.size.height;
    
    self.canyuLabel.frame = CGRectMake(5, imageH-20, 100, 20.5);
    self.zanLabel.frame = CGRectMake(80, imageH-20, 100, 20.5);
    
    CGFloat bcImageH = self.labelBackGroundView.image.size.height;
    self.labelBackGroundView.frame = CGRectMake(0, imageH-bcImageH, screenW, bcImageH);
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
//    [super setSelected:selected animated:animated];
}
- (void)setSelected:(BOOL)selected
{
}
- (void)setSelectedBackgroundView:(UIView *)selectedBackgroundView
{
    
}
- (UIView *)selectedBackgroundView
{
    UIView *view = [[UIView alloc] initWithFrame:self.frame];
    view.backgroundColor = [UIColor redColor];
    return view;
}
@end
